//
//  KBMainViewController.swift
//  VVeibo110
//
//  Created by kongbin on 16/8/9.
//  Copyright © 2016年 kongbin. All rights reserved.
//

import UIKit

class KBMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = KBTabBar()
        //通过KVC给tabBar赋值
        setValue(tabBar, forKey: "tabBar")
        
        
        //设置代理对象
        tabBar.kbDelegate = self
        
addChildViewController1(KBHomeViewController(), tabBarImage: "tabbar_home", title: "首页")
        addChildViewController1(KBMessageViewController(), tabBarImage: "tabbar_message_center", title: "信息")
        addChildViewController1(KBDiscoverViewController(), tabBarImage: "tabbar_discover", title: "发现")
        addChildViewController1(KBProfileViewController(), tabBarImage: "tabbar_profile", title: "我")
        
    }
    
    
    
    
    
    func addChildViewController1(vc :UIViewController,tabBarImage :String,title:String){
        //设置控制器标题
        vc.title = title
        //设置控制器颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        //设置tabbar上的文字颜色
        vc.tabBarItem.image = UIImage (named:tabBarImage)
        vc.tabBarItem.selectedImage = UIImage(named: "\(tabBarImage)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        addChildViewController(UINavigationController(rootViewController: vc))
    
    }
    

 

}

extension KBMainViewController :KBTabBarDelegate{

    func btnClickin() {
        
        print("按钮点击成功")
        
        
    }



}




